/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.cosmact.vxml.model.impl;

import java.util.Collection;

import org.cosmact.vxml.model.Dialog;
import org.cosmact.vxml.model.Document;
import org.cosmact.vxml.model.ModelPackage;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc --> An implementation of the model object '
 * <em><b>Document</b></em>'. <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.cosmact.vxml.model.impl.DocumentImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.cosmact.vxml.model.impl.DocumentImpl#getDialogs <em>Dialogs</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DocumentImpl extends EObjectImpl implements Document {
	/**
         * The default value of the '{@link #getName() <em>Name</em>}' attribute.
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @see #getName()
         * @generated
         * @ordered
         */
	protected static final String NAME_EDEFAULT = "new_form";

	/**
         * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @see #getName()
         * @generated
         * @ordered
         */
	protected String name = NAME_EDEFAULT;

	/**
         * The cached value of the '{@link #getDialogs() <em>Dialogs</em>}' containment reference list.
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @see #getDialogs()
         * @generated
         * @ordered
         */
	protected EList<Dialog> dialogs;

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	protected DocumentImpl() {
                super();
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	protected EClass eStaticClass() {
                return ModelPackage.Literals.DOCUMENT;
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	public String getName() {
                return name;
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	public void setName(String newName) {
                String oldName = name;
                name = newName;
                if (eNotificationRequired())
                        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.DOCUMENT__NAME, oldName, name));
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	public EList<Dialog> getDialogs() {
                if (dialogs == null) {
                        dialogs = new EObjectContainmentEList<Dialog>(Dialog.class, this, ModelPackage.DOCUMENT__DIALOGS);
                }
                return dialogs;
        }

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public void addDialog(Dialog dialog) {
		getDialogs().add(dialog);
		eNotify(new ENotificationImpl(this, Notification.SET,
				ModelPackage.DOCUMENT__DIALOGS, null, dialog));

	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public void removeDialog(Dialog dialog) {
		getDialogs().remove(dialog);
		eNotify(new ENotificationImpl(this, Notification.SET,
				ModelPackage.DOCUMENT__DIALOGS, null, dialog));
	}

	/**
         * <!-- begin-user-doc -->
         * Find the dialog by dialig Id
         * <!-- end-user-doc -->
         * @generated NOT
         */
        public Dialog getDialogById(String dialogId) {
              if(dialogId == null || dialogId.equals("")){
        	  return null;
              }
              if(getDialogs().isEmpty())
        	  return null;
              for(Dialog dialog:getDialogs()){
        	  if(dialogId.equals(dialog.getId())){
        	      return dialog;
        	  }
              }
              return null;
        }

        /**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
                switch (featureID) {
                        case ModelPackage.DOCUMENT__DIALOGS:
                                return ((InternalEList<?>)getDialogs()).basicRemove(otherEnd, msgs);
                }
                return super.eInverseRemove(otherEnd, featureID, msgs);
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
                switch (featureID) {
                        case ModelPackage.DOCUMENT__NAME:
                                return getName();
                        case ModelPackage.DOCUMENT__DIALOGS:
                                return getDialogs();
                }
                return super.eGet(featureID, resolve, coreType);
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
                switch (featureID) {
                        case ModelPackage.DOCUMENT__NAME:
                                setName((String)newValue);
                                return;
                        case ModelPackage.DOCUMENT__DIALOGS:
                                getDialogs().clear();
                                getDialogs().addAll((Collection<? extends Dialog>)newValue);
                                return;
                }
                super.eSet(featureID, newValue);
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	public void eUnset(int featureID) {
                switch (featureID) {
                        case ModelPackage.DOCUMENT__NAME:
                                setName(NAME_EDEFAULT);
                                return;
                        case ModelPackage.DOCUMENT__DIALOGS:
                                getDialogs().clear();
                                return;
                }
                super.eUnset(featureID);
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	public boolean eIsSet(int featureID) {
                switch (featureID) {
                        case ModelPackage.DOCUMENT__NAME:
                                return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
                        case ModelPackage.DOCUMENT__DIALOGS:
                                return dialogs != null && !dialogs.isEmpty();
                }
                return super.eIsSet(featureID);
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	public String toString() {
                if (eIsProxy()) return super.toString();

                StringBuffer result = new StringBuffer(super.toString());
                result.append(" (name: ");
                result.append(name);
                result.append(')');
                return result.toString();
        }

} // DocumentImpl
